package com.tl.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tl.common.annotation.Log;
import com.tl.common.core.controller.BaseController;
import com.tl.common.core.domain.AjaxResult;
import com.tl.common.enums.BusinessType;
import com.tl.app.domain.AppOrderPriceConfig;
import com.tl.app.service.IAppOrderPriceConfigService;
import com.tl.common.utils.poi.ExcelUtil;
import com.tl.common.core.page.TableDataInfo;

/**
 * 订单价格配置Controller
 * 
 * @author suhp
 * @date 2024-07-28
 */
@RestController
@RequestMapping("/app/orderPriceConfig")
public class AppOrderPriceConfigController extends BaseController
{
    @Autowired
    private IAppOrderPriceConfigService appOrderPriceConfigService;

    /**
     * 查询订单价格配置列表
     */
    @PreAuthorize("@ss.hasPermi('app:orderPriceConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppOrderPriceConfig appOrderPriceConfig)
    {
        startPage();
        List<AppOrderPriceConfig> list = appOrderPriceConfigService.selectAppOrderPriceConfigList(appOrderPriceConfig);
        return getDataTable(list);
    }

    /**
     * 导出订单价格配置列表
     */
    @PreAuthorize("@ss.hasPermi('app:orderPriceConfig:export')")
    @Log(title = "订单价格配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppOrderPriceConfig appOrderPriceConfig)
    {
        List<AppOrderPriceConfig> list = appOrderPriceConfigService.selectAppOrderPriceConfigList(appOrderPriceConfig);
        ExcelUtil<AppOrderPriceConfig> util = new ExcelUtil<AppOrderPriceConfig>(AppOrderPriceConfig.class);
        util.exportExcel(response, list, "订单价格配置数据");
    }

    /**
     * 获取订单价格配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:orderPriceConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appOrderPriceConfigService.selectAppOrderPriceConfigById(id));
    }

    /**
     * 新增订单价格配置
     */
    @PreAuthorize("@ss.hasPermi('app:orderPriceConfig:add')")
    @Log(title = "订单价格配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppOrderPriceConfig appOrderPriceConfig)
    {
    	List<AppOrderPriceConfig> aopcList=appOrderPriceConfigService.selectAppOrderPriceConfigList(appOrderPriceConfig);
    	if(aopcList.size()>0) {
    		return AjaxResult.error("此配置已存在！");
    	}
        return toAjax(appOrderPriceConfigService.insertAppOrderPriceConfig(appOrderPriceConfig));
    }

    /**
     * 修改订单价格配置
     */
    @PreAuthorize("@ss.hasPermi('app:orderPriceConfig:edit')")
    @Log(title = "订单价格配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppOrderPriceConfig aopc)
    {
    	List<AppOrderPriceConfig> aopcList=appOrderPriceConfigService.selectAppOrderPriceConfigList(aopc);
    	if(aopcList.size()>0&&aopc.getId()!=aopcList.get(0).getId()) {
    		return AjaxResult.error("此配置已存在！");
    	}
        return toAjax(appOrderPriceConfigService.updateAppOrderPriceConfig(aopc));
    }

    /**
     * 删除订单价格配置
     */
    @PreAuthorize("@ss.hasPermi('app:orderPriceConfig:remove')")
    @Log(title = "订单价格配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appOrderPriceConfigService.deleteAppOrderPriceConfigByIds(ids));
    }
}
